<template>
	<view id="assemble" @click="assembleFlag=false">
		<view v-for="(item,index) in opusDirectory" :key="index">
			<view class="left" style="background: #f7f7f7;padding-bottom: 2.5rem;">
				<view class="assemble_mainImage">
					<image :src="item.cover" mode="widthFix" />
				</view>
				<view class="assemble_mainImage_name">
					{{item.title}}
				</view>
				<view class="assemble_main_briefly">
					{{item.content}}
				</view>
				<view class="assemble_author" @click="gotoPersonalData(item.user.id)">
					<view class="assemble_author_headImg">
						<image :src="item.user.headimg" mode="aspectFit"></image>
					</view>
					<view class="assemble_author_name">
						{{item.user.nickname}}
					</view>
				</view>
				<view class="iconType" v-if="item.user.id == userInfo.id"> 
					<view class="custom-icon custom-icon-fenxiang"> <text>分享</text> </view>
					<view class="custom-icon custom-icon-bianji" @click="updateOpus(item)" v-if="item.user.id == userInfo.id"> <text>编辑</text> </view>
				</view>
				<view class="iconTypes" v-else>
					<view class="custom-icon custom-icon-fenxiang"> <text>分享</text> </view>
				</view>

			</view>
			<view class="">
				<dynamicList :list="list" :initial-value.sync="list"></dynamicList>
			</view>
			
			<!-- <view class="right" style="background: #fff;padding-top: 2.5rem;">
				<view>
					<view class="assemble_search">
						<view class="custom-icon custom-icon-qiehuan" @click.stop="assembleFlag=!assembleFlag">
							{{pickSort}}
						</view>
					</view>
					<view v-show="assembleFlag" class="privacy">
						<view v-for="(item,index) in assembleSortList" @click="pickItem(item)">{{item.name}}</view>
					</view>
				</view>
				<UnlockOpus :list="UnlockOpusList" :initial-value.sync="UnlockOpusList"></UnlockOpus>

			</view> --> <!-- 这里关闭 right 标签 -->
			<!-- <view style="height: 100rpx;background: #fff;"></view> --> <!-- 修改为结束标签 -->
		</view>
	</view>
</template>


<script>
	import {
		mapState,
		mapActions
	} from "vuex"
	import dynamicList from '@/components/dynamicList/dynamicList.vue';
	import dynamic from '@/components/Segmenter/dynamic.vue';
	export default {
		components: {dynamic},
		data() {
			return {
				DTid:'',
				id:'',
				list:[],
				page: 1,
				limit: 10,
				status: 'more' ,// 加载状态: 'more', 'loading', 'noMore'
				opusDirectory: [],
				pickSort: '最新',
				assembleFlag: false,
				UnlockOpusList: [{
					name: '《困兽之染》第36话 放我走',
					collectFlag: false
				}, {
					name: '《困兽之染》第35话 我爱你',
					collectFlag: false
				}],
				assembleSortList: [{
						id: 0,
						name: '正序'
					},
					{
						id: 1,
						name: '倒序'
					},
					{
						id: 2,
						name: '最早'
					},
					{
						id: 3,
						name: '最新'
					},
				]
			}
		},
		onLoad(option) {
			console.log("option", option)
			this.id=option.id;
			this.getDetail(option.id);
		},
		// onBackPress(event) {
		// 	console.log("event", event)
		// 	this.gotoPersonalData();
		// 	return true;
		// },
		comments:{
			...mapState('user', ['userInfo']),
		},
		methods: {
			// 监听触底
			onReachBottom() {
				// 检查是否正在加载和是否还有更多数据
				if (this.status === 'more') {
					this.Department(this.DTid); // 获取下一页数据
				}
			}, 
			gotoPersonalData(id){
				uni.redirectTo({
					url: '/pages/home/PersonalData/PersonalData?id=' + id
				});
			},
			getDetail(id) {
				console.log(id);
				this.$api.getDetail({
					id: id
				}).then(res => {
					console.log("res作品详情", res.data)
					this.opusDirectory.push(res.data)
					this.DTid = res.data.id
					this.Department(res.data.id)
				})
			},
			Department(id){
				this.status = 'loading'; // 设置加载状态为 loading
				this.$api.portfolioBelow({
					id:id,
					page: this.page,
					limit: this.limit,
				}).then(res=>{
					// this.list = res.data.data
				        console.log(res.data && res.data.data.length < 1,'aaaaaaaaaaa')
					if (res.data && res.data.data.length < 1) {
						
						this.status = 'noMore'; // 标记没有更多数据
					} else {
						let resList = res.data.data; // 获取实际数据
						this.list = this.list.concat(resList); // 合并新数据
						this.status = 'more'; // 重置状态为 more
						this.page += 1; // 增加页码
					}
				}).catch(error => {
						console.error("请求出错:", error); // 错误处理
						this.status = 'more'; // 错误时仍然可以加载更多
					});
			},
			updateOpus(item) {
				console.log("编辑", item)
				uni.navigateTo({
					url: "/pages/home/PersonalData/newOpusList?id=" + item.id
				})
			},
			pickItem(item) {
				console.log(item);
				this.pickSort = item.name;
				this.assembleFlag = false;
			},

		}
	}
</script>

<style scoped lang="scss">
	#assemble {
		width: 100%;
		margin: auto;
		background: #f7f7f7;
	}

	.assemble_mainImage {
		width: 70%;
		margin: auto;
		margin-top: 40rpx;
		border-radius: 50rpx;
	// border: 1rpx solid red;

		image {
			width: 100%;
			display: block;
			border-radius: 50rpx;
		}
	}

	.assemble_mainImage_name {
		width: 80%;
		margin: auto;
		padding: 20rpx 0;
		text-align: center;
		font-size: 40rpx;
		font-weight: bold;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.assemble_main_briefly {
		width: 90%;
		line-height: 1;
		padding: 20rpx 0;
		font-size: 30rpx;
		color: #000;
		margin: auto;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.assemble_author {
		
		padding: 20rpx;
		display: flex;
		align-items: center;
		text-align: center;
		justify-content: center;

		.assemble_author_headImg {
			
			display: flex;
			align-items: center;

			image {
				// width: 70%;
				width: 100rpx;
				height: 100rpx;
				border-radius: 100rpx;
				margin-right:20rpx;
			}
		}

		.assemble_author_name {
			
			font-size: 30rpx;
			display: flex;
			align-items: center;
			
		}



	}

	.iconType {
		width: 40%;
		text-align: center;
		margin: auto;
		margin-top: 40rpx;
		display: flex;
		justify-content: space-between;

		.custom-icon {
			display: flex;
		    align-items: center;
			justify-content: center;
			text{
				font-size: 28rpx;
				color: #000;
				margin-left: 10rpx;
			}
		
		}
	}
	.iconTypes {
		width: 40%;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: auto;
		margin-top: 40rpx;
		 
	
		.custom-icon {
			display: flex;
		    align-items: center;
			justify-content: center;
			text{
				font-size: 28rpx;
				color: #000;
				margin-left: 10rpx;
			}
		
		}
	}

	.assemble_search {
		width: 90%;
		margin: auto;
		line-height: 80rpx;
		display: flex;
		justify-content: flex-end;
	}

	.privacy {
		width: 15%;
		position: absolute;
		right: 20rpx;
		//#ifdef MP-WEIXIN
		width: 16%;
		top: 45.5rem;
		//#endif
		background: #fff;
		z-index: 999;
		border: #e5e5e5 2rpx solid;

		view {
			width: 90%;
			margin: auto;
			line-height: 80rpx;
			// border: 2rpx red solid;
			text-align: center;
		}
	}
</style>